class_name PeriodEffectComponent
extends GameplayEffectComponent

## 效果距离下个触发周期的时间
var elapsed_next_period_time: float = 0.0

##
var _sources: Array


func _on_attach(source: Variant) -> void:
	if _sources.find(source) == -1:
		_sources.append(source)
		elapsed_next_period_time = component_asset.period


func _on_update(delta: float) -> void:
	elapsed_next_period_time -= delta
	
	while elapsed_next_period_time <= 0.0:
		parent.on_periodic_tick()
		elapsed_next_period_time += component_asset.period


func _on_periodic_tick() -> void:
	parent.apply_effect()


func _on_duration_end() -> void:
	pass


func _on_stack_update(_variation: int) -> void:
	pass


func _on_detach(_source: Variant) -> void:
	pass
